/** Indexed Access Types
 * 通过 索引访问类型
 */

type P = {name: string; age: number; alive: boolean}
type Age = P["age"]; // number;  对应的是p的age这个字段类型 最简单
type M = P["age" | "name"]; // string | number;
type MM = P[keyof P]; // string | number | boolean



// 下面这个很有意思

const myArr = [
    {name: "foo", age: 13},
    {name: "boo", age: 12}
]
type V = typeof myArr; //  { name: string; age: number; }[]
type VV = typeof myArr[number] // {name: string; age: number}
type VVV = typeof myArr[number]["age"] // number

const name1 = "name";
// type NameType = VV[name1]; // 同样的问题，平行世界
type NameType = VV[typeof name1]; // 需要typeof转换下


// 扩展下
// 这里的类型推断是 string[];如果这里的string希望改成"a" | "b" | "c"；怎么处理？
const tmepList = ["a", "b", "c"];
// 方法1：
type TempList = "a" | "b" | "c";
const t1: TempList[] = ["a", "b", "c"];
// 方法2:
function tuple<T extends string[]>(...arg: T): T {
    return arg;
}
const list = tuple("a", "b", "c");
type LLL = (typeof list)[number];

